package com.th.review;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;

/**
 * @author ThreePure
 * @date 2022/5/23 16:09
 * @description: 增强类
 * @since 1.8
 */
public class StrangeClass implements InvocationHandler {
    private Object obj;

    public StrangeClass(Object obj) {
        this.obj = obj;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //前置处理
        System.out.println("[Before]"+method.getName()+",and the args :"+ Arrays.toString(args));
        //执行方法
        Object res = method.invoke(obj, args);
        // 后置处理
        System.out.println("[After:]"+obj.toString());
        return res;
    }
}
